var util = require('../utils/util.js');
var app = getApp();
Page({
    data: {
        imgs:["../image/logo.png"],
        flag:0
    },

    // 初始化设置
    onLoad: function () {
        wx.getStorage({
            key: 'flag',
            success: function (res) {
                console.log(res.data);
            }
        })
        wx.setStorage({
            key: 'flag',
            data: 1
        })
        var that = this;
        var openId = wx.getStorageSync('openId');
        wx.request({
            url: 'https://xcx.ahdhst.cn/tp/public/index.php/Index/sign/isOpenId',  //根据经纬度转换成具体地址
            data: {
                "key": app.globalData.key,
                "openId": openId,
            },
            method: 'POST',
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function (res) {
                setTimeout(function () {
                        if (res.data.isOpenId == 1) {
                            wx.redirectTo({
                                url: '/pages/public/public',
                            })
                        } else {
                            wx.redirectTo({
                                url: '/pages/login',
                            })
                        }
                    },2000
                )
            },
            fail: function () {
                // fail
                console.log("请求失败");
            },
            complete: function () {
                // complete
                console.log("请求完成");
            }
        })
    },

    start: function () {
        /*wx.getStorage({
         key: 'flag',
         success: function (res) {
         console.log(res.data);
         }
         })
         wx.setStorage({
         key: 'flag',
         data: 1
         })
         var that = this;
         var openId = wx.getStorageSync('openId');
         wx.request({
         url: 'https://xcx.ahdhst.cn/tp/public/index.php/Index/sign/isOpenId',  //根据经纬度转换成具体地址
         data: {
         "openId": openId,
         },
         method: 'POST',
         header: {
         "Content-Type": "application/x-www-form-urlencoded"
         },
         success: function (res) {
         setTimeout(function () {
         if (res.data.isOpenId == 1) {
         wx.redirectTo({
         url: '/pages/public/public',
         })
         } else {
         wx.navigateTo({
         url: '/pages/login',
         })
         }
         }
         )
         },
         fail: function () {
         // fail
         console.log("请求失败");
         },
         complete: function () {
         // complete
         console.log("请求完成");
         }
         })*/
    },

    onShow: function () {
        wx.getStorage({
            key: 'flag',
            success: function (res) {
                console.log('C');
                console.log(res.data);
                if (res.data != 1 && res.data != 2) {
                    var that = this;
                    var openId = wx.getStorageSync('openId');
                    wx.request({
                        url: 'https://xcx.ahdhst.cn/tp/public/index.php/Index/sign/isOpenId',  //
                        data: {
                            "key": app.globalData.key,
                            "openId": openId,
                        },
                        method: 'POST',
                        header: {
                            "Content-Type": "application/x-www-form-urlencoded"
                        },
                        success: function (res) {
                            setTimeout(function () {
                                    if (res.data.isOpenId == 1) {
                                        wx.redirectTo({
                                            url: '/pages/public/public',
                                        })
                                    } else {
                                        wx.redirectTo({
                                            url: '/pages/login',
                                        })
                                    }
                                }, 2000
                            )
                        },
                        fail: function () {
                            // fail
                            console.log("请求失败");
                        },
                        complete: function () {
                            // complete
                            console.log("请求完成");
                        }
                    })
                }
                wx.setStorage({
                    key: 'flag',
                    data: 2
                })
            }
        })
    },

    onReady: function () {

    },

    onUnload: function () {

    },

    onHide: function () {

    }
})